
import config from "../config/config";
import {promisic} from "../miniprogram_npm/lin-ui/utils/util";

class Http {
    static async request({
                            url,
                            data,
                            method = 'GET'
                         }){
        let res;
        try {
            res = await promisic(wx.request)({
                url: `${config.apiBaseUrl}${url}`,
                data,
                method,
                header: {
                    'content-type': 'application/json',
                    'X-Yd-Token': wx.getStorageSync('token')
                }
            })
        } catch (e) {
            console.log(e)
            wx.showToast({
                icon: "none",
                title: "网络中断、超时或其他异常",
                duration: 3000
            })
        }

        console.log(res)
        if (!res.data.success) {
            wx.showToast({
                icon: "none",
                title: res.data.errMsg,
                duration: 3000
            })
        }

        return res.data.data
    }
}

export {
    Http
}